using System;
using System.Collections;
using System.Collections.Generic;
using Unity.Profiling.LowLevel.Unsafe;
using UnityEngine;

namespace Super
{
	[RequireComponent(typeof(Collider2D))]
	public class SpriteBrush : MonoBehaviour
	{
		public bool isEnter;
		public Dictionary<MouseKey, Action> actionDict = new Dictionary<MouseKey, Action>()
		{
			{MouseKey.Left, null},
			{MouseKey.Middle, null},
			{MouseKey.Right, null},
		};
		
		public void OnEnable()
		{
			EventManager.Register<MouseDownGE>(OnMouseDownGE);
		}
		
		public void SetAction(MouseKey key, Action action)
		{
			actionDict[key] = action;
		}
		
		private void OnMouseEnter()
		{
			if (InputManager.Ins.isMouseOverUI) return;
			isEnter = true;
			if (!InputManager.Ins.mouseInfo.isHold) return;
			MouseKey holdKey = InputManager.Ins.mouseInfo.holdKey;
			actionDict[holdKey]?.Invoke();
		}
		
		private void OnMouseExit()
		{
			isEnter = false;
		}
		
		private void OnMouseDownGE(MouseDownGE evt)
		{
			if (!isEnter) return;
			if (InputManager.Ins.isMouseOverUI) return;
			MouseKey holdKey = InputManager.Ins.mouseInfo.holdKey;
			actionDict[holdKey]?.Invoke();
		}
		
		private void OnDestroy()
		{
			EventManager.UnRegisterAll(this);
		}
		
		private void OnDisable()
		{
			EventManager.UnRegisterAll(this);
		}
	}

}

